package com.iflytek.yousheng;

import com.alibaba.fastjson.JSONObject;
import com.iflytek.yousheng.Util.OkHttp3Utils;
import com.iflytek.yousheng.Util.SginUtils;
import com.iflytek.yousheng.Util.SignUtils2;

import java.io.IOException;
import java.util.Objects;
import java.util.UUID;

/**
 * Hello world!
 */
public class App {

    private final static String url = "http://newserver.xfyousheng.com/";
    private final static String addpath = "api/v1/vir/add";
    private final static String appId = "xxxxxxxxx";//替换授权的appid
    private final static String appKey = "xxxxxxxxxxxxxxxxxxxxxxx";//替换对于的appkey
    private final static int anchorId = 000000000;//替换授权的形象id
    private final static String vcn = "xxxxxxxxxxxxxxxxx";//替换授权的声音id
    private final static String text = "[p1000]欢迎来到科大讯飞虚拟人视频合成";//[p1000]是静音标签，1000是毫秒数

    public static void main(String[] args) {
        AddReq();
    }


    private static void AddReq() {
        String requrl = String.format("%s%s",url,addpath);
        JSONObject req = new JSONObject();

        JSONObject base = new JSONObject();

        base.put("appid", appId);
        base.put("sid", UUID.randomUUID().toString());
        base.put("timestamp", System.currentTimeMillis());

        JSONObject param = new JSONObject();
        param.put("anchorId", anchorId);
        param.put("text", text);
        param.put("vcn",vcn);
//        param.put("location","-380");//虚拟人位移参数
        param.put("format","mp4");//webm是透明背景
        param.put("bgType",0);//图片0   视频1
//        param.put("bgUrl","https://域名/图片.png/jpg/webm");//可访问到的图片网络地址
        param.put("width","1080");//分辨率宽
        param.put("height","1920");//分辨率高
//        param.put("scale",0.9);//虚拟人缩放比例，取值[0.1,1]
//        param.put("mask","[0,140,985,1530]");//虚拟人形象裁剪，默认值[0,0,1080,1920]，依次是从左到右裁剪，从上到下裁剪，从右到左裁剪，从下到上裁剪，

//        param.put("translation","-380");//虚拟人位移参数



        req.put("base", base);
        req.put("param", param);

        String sign = SginUtils.buildSign(req, appKey);
        base.put("sign", sign);


        String reqString = req.toJSONString();
        System.out.printf("请求体:%s \n", reqString);

        String respBody = "";
        try {
            respBody = OkHttp3Utils.postJson(requrl, reqString);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.printf("返回结果:%s \n", respBody);
    }



}
